using UnityEngine;
using System.Collections;

public class DistanceView : MonoBehaviour
{
    private string MOUSESCROLLWHEEL = "Mouse ScrollWheel";

    private bool isFirstPerson = false;

    // Use this for initialization
    void Start()
    {
        //this.transform.localPosition = ShortMemory.Instance.cameraDistance;
        //Player.GetInstance().FadeTop.ChangeRadius((int)this.transform.localPosition.y);
        //this.ScrollChanged();
    }

    // Update is called once per frame
    void Update()
    {
        //if (Input.GetAxis(MOUSESCROLLWHEEL) != 0)
        //{
        //    this.ScrollChanged();
        //}
    }

    private void ScrollChanged()
    {
        Vector3 distance = this.transform.localPosition;
        distance.y -= Input.GetAxis(MOUSESCROLLWHEEL);
        distance.z -= Input.GetAxis(MOUSESCROLLWHEEL);

        this.ConstrainNumber(ref distance.y, 0, 10);
        this.ConstrainNumber(ref distance.z, 0, 10);


        if (distance.y == 0 && distance.z == 0 && isFirstPerson == false)
            this.ActivateFirstPerson();
        else if (distance.y != 0 && distance.z != 0 && isFirstPerson == true)
            this.DeactivateFirstPerson();

        ShortMemory.Instance.cameraDistance = distance;

        this.transform.localPosition = distance;

        if (!this.isFirstPerson)
            Player.GetInstance().FadeTop.ChangeRadius((int)distance.y);

        this.transform.localPosition = distance;
    }

    private void ActivateFirstPerson()
    {
        this.isFirstPerson = true;
        this.transform.parent.GetComponent<MouseLook>().minimumY = -90;
    }
    private void DeactivateFirstPerson()
    {
        this.isFirstPerson = false;
        this.transform.parent.GetComponent<MouseLook>().minimumY = -22.5f;
    }


    private void ConstrainNumber(ref float number,int minimum, int maximum)
    {
        if (number < minimum)
            number = minimum;
        if (number > maximum)
            number = maximum;
    }
}
